package com.ljb.flabbybird;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.AttributeSet;

/**
 * Created by ljb on 2017/7/7.
 */

public class FlabbyBird extends BaseSurfaceView {


    private Bitmap mBg;//背景

    public FlabbyBird(Context context) {
        this(context, null);
    }

    public FlabbyBird(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public FlabbyBird(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initBitmaps();//初始化背景
    }

    //初始化背景
    private void initBitmaps() {
//        mBg = loadImageByResId(R.drawable.bg);
    }

    @Override
    protected void drawSomething(Canvas canvas) {
        super.drawSomething(canvas);
        drawBg(canvas);//绘制背景
    }

    //绘制背景
    private void drawBg(Canvas canvas) {
        canvas.drawBitmap(mBg, null, mSurfaceViewRect, null);
    }

    //通过资源id加载图片
    private Bitmap loadImageByResId(int resId) {
        return BitmapFactory.decodeResource(getResources(), resId);
    }
}
